<?php

namespace Proyecto\MainBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;

/**
 * Usuario
 *
 * @ORM\Table(name="usuario")
 * @ORM\Entity
 * 
 */
class Usuario implements AdvancedUserInterface, \Serializable
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     * 
     */
    private $id;

    /**
     * @var string
     * 
     * @ORM\Column(name="usuario", type="string", length=45, nullable=false)
     * 
     */

    private $usuario;

    /**
     * @var string
     * 
     * @ORM\Column(name="password", type="string", length=45, nullable=false)
     * 
     */
    private $password;

    /**
     * @var boolean
     * 
     * @ORM\Column(name="cv_publico", type="boolean", nullable=false)
     * 
     */
    private $cvPublico;

    /**
     * @var boolean
     *
     * @ORM\Column(name="activo", type="boolean", nullable=false)
     * 
     */
    private $activo;

    /**
     * @var string
     *
     * @ORM\Column(name="nomyap", type="string", length=100, nullable=false)
     * 
     */
    private $nomyap;

    /**
     * @var string
     * 
     * @ORM\Column(name="email", type="string", length=50, nullable=false)
     * 
     */
    private $email;

    /**
     * @var string
     *
     * @ORM\Column(name="telefono", type="string", length=45, nullable=true)
     */
    private $telefono;

    /**
     * @var \Perfil
     *
     * @ORM\ManyToOne(targetEntity="Perfil")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="perfil", referencedColumnName="id")
     * })
     * 
     */
    private $perfil;



    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set usuario
     *
     * @param string $usuario
     * @return Usuario
     */
    public function setUsuario($usuario)
    {
        $this->usuario = $usuario;
    
        return $this;
    }

    /**
     * Get usuario
     *
     * @return string 
     */
    public function getUsuario()
    {
        return $this->usuario;
    }

    /**
     * Set password
     *
     * @param string $password
     * @return Usuario
     */
    public function setPassword($password)
    {
        $this->password = $password;
    
        return $this;
    }

    /**
     * Get password
     *
     * @return string 
     */
    public function getPassword()
    {
        return $this->password;
    }

    /**
     * Set cvPublico
     *
     * @param boolean $cvPublico
     * @return Usuario
     */
    public function setCvPublico($cvPublico)
    {
        $this->cvPublico = $cvPublico;
    
        return $this;
    }

    /**
     * Get cvPublico
     *
     * @return boolean 
     */
    public function getCvPublico()
    {
        return $this->cvPublico;
    }

    /**
     * Set activo
     *
     * @param boolean $activo
     * @return Usuario
     */
    public function setActivo($activo)
    {
        $this->activo = $activo;
    
        return $this;
    }

    /**
     * Get activo
     *
     * @return boolean 
     */
    public function getActivo()
    {
        return $this->activo;
    }

    /**
     * Set nomyap
     *
     * @param string $nomyap
     * @return Usuario
     */
    public function setNomyap($nomyap)
    {
        $this->nomyap = $nomyap;
    
        return $this;
    }

    /**
     * Get nomyap
     *
     * @return string 
     */
    public function getNomyap()
    {
        return $this->nomyap;
    }

    /**
     * Set email
     *
     * @param string $email
     * @return Usuario
     */
    public function setEmail($email)
    {
        $this->email = $email;
    
        return $this;
    }

    /**
     * Get email
     *
     * @return string 
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Set telefono
     *
     * @param string $telefono
     * @return Usuario
     */
    public function setTelefono($telefono)
    {
        $this->telefono = $telefono;
    
        return $this;
    }

    /**
     * Get telefono
     *
     * @return string 
     */
    public function getTelefono()
    {
        return $this->telefono;
    }

    /**
     * Set perfil
     *
     * @param \Proyecto\MainBundle\Entity\Perfil $perfil
     * @return Usuario
     */
    public function setPerfil(\Proyecto\MainBundle\Entity\Perfil $perfil = null)
    {
        $this->perfil = $perfil;
    
        return $this;
    }

    /**
     * Get perfil
     *
     * @return \Proyecto\MainBundle\Entity\Perfil 
     */
    public function getPerfil()
    {
        return $this->perfil;
    }
	
	public function getRoles()
	{
	    return array('ROLE_'.$this->getPerfil()->getPerfil());
	}
	
	public function getUsername()
	{
	    return $this->getUsuario();
	}
	
	public function getSalt()
	{
	    return 'sha512';
	}
	
	public function eraseCredentials()
    {
    }
	
    public function serialize()
    {
        return serialize(array(
            $this->id,
            
        ));
    }

   
    public function unserialize($serialized)
    {
        list (
            $this->id,
        ) = unserialize($serialized);
    }
    
    public function __toString(){
		return $this->nomyap;
   }
   
    public function isAccountNonExpired()
    {
        return true;
    }

    public function isAccountNonLocked()
    {
        return true;
    }

    public function isCredentialsNonExpired()
    {
        return true;
    }

    public function isEnabled()
    {
        return $this->getActivo();
    }
}